package com.ruoyi.papers.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.papers.domain.JwResearchPapers;
import com.ruoyi.papers.service.IJwResearchPapersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 论文发情况Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/papers/papers")
public class JwResearchPapersController extends BaseController
{
    @Autowired
    private IJwResearchPapersService jwResearchPapersService;

    /**
     * 查询论文发情况列表
     */
    @PreAuthorize("@ss.hasPermi('papers:papers:list')")
    @GetMapping("/list")
    public TableDataInfo list(JwResearchPapers jwResearchPapers)
    {
        startPage();
        List<JwResearchPapers> list = jwResearchPapersService.selectJwResearchPapersList(jwResearchPapers);
        return getDataTable(list);
    }

    /**
     * 导出论文发情况列表
     */
    @PreAuthorize("@ss.hasPermi('papers:papers:export')")
    @Log(title = "论文发情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JwResearchPapers jwResearchPapers)
    {
        List<JwResearchPapers> list = jwResearchPapersService.selectJwResearchPapersList(jwResearchPapers);
        ExcelUtil<JwResearchPapers> util = new ExcelUtil<JwResearchPapers>(JwResearchPapers.class);
        util.exportExcel(response, list, "论文发情况数据");
    }

    /**
     * 获取论文发情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('papers:papers:query')")
    @GetMapping(value = "/{rpId}")
    public AjaxResult getInfo(@PathVariable("rpId") Long rpId)
    {
        return success(jwResearchPapersService.selectJwResearchPapersByRpId(rpId));
    }

    /**
     * 新增论文发情况
     */
    @PreAuthorize("@ss.hasPermi('papers:papers:add')")
    @Log(title = "论文发情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JwResearchPapers jwResearchPapers)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        jwResearchPapers.setDeptId(104L);
        jwResearchPapers.setUserId(user.getUserId());
        return toAjax(jwResearchPapersService.insertJwResearchPapers(jwResearchPapers));
    }

    /**
     * 修改论文发情况
     */
    @PreAuthorize("@ss.hasPermi('papers:papers:edit')")
    @Log(title = "论文发情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JwResearchPapers jwResearchPapers)
    {
        return toAjax(jwResearchPapersService.updateJwResearchPapers(jwResearchPapers));
    }

    /**
     * 删除论文发情况
     */
    @PreAuthorize("@ss.hasPermi('papers:papers:remove')")
    @Log(title = "论文发情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rpIds}")
    public AjaxResult remove(@PathVariable Long[] rpIds)
    {
        return toAjax(jwResearchPapersService.deleteJwResearchPapersByRpIds(rpIds));
    }
}
